package com.yxt.qmgf.userinfo.view;

import com.yxt.qmgf.common.ClientSession;
import com.yxt.qmgf.common.view.CdzAlert;
import com.yxt.qmgf.userinfo.ctrl.UserInfoController;
import com.yxt.qmgf.userinfo.vo.UserInfoVO;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.control.Alert;
import javafx.scene.control.Tab;
import javafx.scene.layout.Pane;

import java.io.IOException;
import java.net.URL;

public class UserInfoTab extends Tab {
    private static volatile UserInfoTab instance;

    public  UserInfoVO vo = null;

    private UserInfoTab() {
        this("个人信息");
    }



    private UserInfoTab(String str) {
        super(str);
        this.vo = vo;
        initView();
    }





    public static UserInfoTab getInstance() {
        if (null == instance) {
            synchronized (UserInfoTab.class) {
                if (null == instance) {
                    instance = new UserInfoTab();
                }
            }
        }
        return instance;
    }

    private void initView() {
        UserInfoVO vo =(UserInfoVO) ClientSession.getAttribute("user_info");
        if (vo != null) {
            URL url = getClass().getResource("/fxml/UserInfo/UserInfo.fxml");
            FXMLLoader fxmlLoader = new FXMLLoader();
            fxmlLoader.setLocation(url);
            fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
            try {
                Pane pane = fxmlLoader.load();
                pane.getStylesheets().add(getClass().getResource("/css/yxt.css").toExternalForm());
                setContent(pane);
            } catch (IOException e) {
                e.printStackTrace();
            }
            setClosable(true);
            UserInfoController controller =fxmlLoader.getController();
            controller.setOff(vo);
        } else {
            // 处理 vo 为 null 的情况，例如显示错误信息
            new CdzAlert(Alert.AlertType.WARNING, "用户信息未正确获取，请重新登录").show();
        }
    }

}
